﻿using System;
using System.Windows;
using System.Windows.Controls;
using uTrade.Core;

namespace uTrade.Views
{
    /// <summary>
    /// BackTestView.xaml 的交互逻辑
    /// </summary>
    public partial class BackTestView : UserControl
    {
        public BackTestView()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 窗口动态初始化
        /// </summary>
        public void Init()
        {
            //3.开始时间，结束时间
            dp_BeginTime.SelectedDate = DateTime.Today.AddYears(-1);
            dp_EndTime.SelectedDate = DateTime.Today;
        }

        private void btn_Simulate_Click(object sender, RoutedEventArgs e)
        {
            if (this.cmbx_Stratagies.SelectedIndex < 0) return;
            if (this.cmbx_Interval.SelectedIndex < 0) return;

            Strategy stra = (Strategy)Activator.CreateInstance((Type)this.cmbx_Stratagies.SelectedItem);

            //TODO---参数配置---
            //if (stra.GetParams().Trim('(', ')').Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Length >= 1)
            //{
            //    PropertyGrid fp = new PropertyGrid();

            //    //参数配置
            //    fp.DataContext = stra;
            //    fp.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            //    if (fp.ShowDialog() != true) return;
            //}

            //StrategyConfig strategy = AddStra(stra, this.cmbx_Interval.Text, this.dp_BeginTime.DisplayDate, this.dp_EndTime.DisplayDate);

            //数据加载
            //LoadDataBar(strategy);
        }

        //加载测试指定行的策略的
        private void LoadDataBar(StrategyConfig config)
        {
            //var inst = row.Cells["Instrument"].Value.ToString();
            //var instOrder = row.Cells["InstrumentOrder"].Value.ToString();
            //var interval = row.Cells["Interval"].Value.ToString();
            //var stra = _dicStrategies[row.Cells["StraName"].Value.ToString()];
            //var begin = ((DateTime)row.Cells["BeginDate"].Value).ToString("yyyyMMdd");
            //var end = row.Cells["EndDate"].Value == null ? DateTime.Today.AddDays(7).ToString("yyyyMMdd") : ((DateTime)row.Cells["EndDate"].Value).AddDays(1).ToString("yyyyMMdd");

            //this.DataGridViewStrategies.Rows[rid].Cells["Loaded"].Value = "加载中...";
        }
    }
}